package com.example.bma;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity2 extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        EditText edit_height=findViewById(R.id.edit_height);
        EditText edit_weight=findViewById(R.id.edit_weight);
        Button btn_cal= findViewById(R.id.btn_cal);
        Button btn_reset=   findViewById(R.id.btn_reset);
        TextView texts=findViewById(R.id.texts);
        btn_cal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String str_height=edit_height.getText().toString();
                String str_weight=edit_weight.getText().toString();
              int height=  Integer.parseInt(str_height);
                int weight=  Integer.parseInt(str_weight);
                Log.i("anc","s"+height+"/w"+weight);
                double bml=weight*10000/height/height;
                texts.setText(bml+"");
                if(bml<18.5)
                    texts.setText("计算结果:轻体重");
              else   if(bml<24&&bml>=18.5)
                    texts.setText("计算结果:健康体重");
               else if(bml<28&&bml>=24)
                    texts.setText("计算结果:超重");
               else
                    texts.setText("计算结果:肥胖");
            }
        });
        btn_reset.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                edit_height.setText("");
                edit_weight.setText("");
                texts.setText("计算结果:");

            }
        });
    }
}